using System.Data;
using NUnit.Framework;
using NUnitAddinAttributes;
using SDG.UnitTesting.Remoting;

namespace SDG.UnitTesting.SimpleTalk.Tests
{
    [TestFixture]
    [SDG]
    //[SDG("D:\Red Gate\SQL Data Generator\SQLDataGenerator.exe")] //Overload to set console application location.
    public class DataAccessTests : SDGContext
    {
        [Test]
        [ExecuteSql(ExecuteWhen = TestSequence.Before,  //Taken from Testing Times Ahead: Extending NUnit
                    Script = "DELETE FROM [Order Details]; DELETE FROM [Orders]; DELETE FROM CustomerCustomerDemo; DELETE FROM Customers", 
                    Connection = "Server=(local);Database=Northwind;Integrated Security=True")]
        public void GetAllCustomers_EmptyDatabase_ZeroRows()
        {
            DataTable dt = DataAccess.GetAllCustomers();
            Assert.AreEqual(0, dt.Rows.Count);
        }

        [Test]
        [SDGExecute("Database\\NorthwindCustomers_Orders.sqlgen")]
        public void GetAllCustomers_SDGProject_1000Rows()
        {
            DataTable dt = DataAccess.GetAllCustomers();
            Assert.AreEqual(1000, dt.Rows.Count);
        }

        [Test]
        [SDGExecute("Database\\NorthwindCustomers_Orders.sqlgen")]
        public void GetCustomerByID_SDGProject_1RowReturned()
        {
            DataTable dt = DataAccess.GetCustomerByID("00040");
            Assert.AreEqual(1, dt.Rows.Count);
        }

        [Test]
        [SDGExecute("Database\\NorthwindCustomers_Orders.sqlgen")]
        public void GetCustomerByID_SDGProject_CorrectCustomer()
        {
            DataTable dt = DataAccess.GetCustomerByID("00040");

            Assert.AreEqual("00040", dt.Rows[0]["CustomerID"]);
            Assert.AreEqual("Suppebentor Holdings ", dt.Rows[0]["CompanyName"]);
            Assert.AreEqual("Bobbi Yates", dt.Rows[0]["ContactName"]);
            Assert.AreEqual("Web", dt.Rows[0]["ContactTitle"]);
            Assert.AreEqual("564 White Old Freeway", dt.Rows[0]["Address"]);
        }
    }
}
